<%@page import="java.io.InputStream"%>
<%@page import="java.net.HttpURLConnection"%>
<%@page import="java.net.URLDecoder"%>
<%@page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page session="false"%>
<%@page import="java.net.URL"%>
<%
	String fileName = request.getParameter("fileName");
	fileName = URLDecoder.decode(fileName);
	System.out.println("3");
	//response.sendRedirect(fileName);
	InputStream is = null;
	ServletOutputStream sos = null;
	try {
		response.setContentType("application/force-download");
		String name = fileName.substring(fileName.lastIndexOf("/") + 1);
		response.setHeader("Content-Disposition", "attachment;filename=" + name);
		URL url = new URL(fileName);
		HttpURLConnection conn = (HttpURLConnection)url.openConnection();
		conn.setDoInput(true);
		conn.connect();
		is = conn.getInputStream();
		byte[] buf = new byte[2048];
		int len;
		sos = response.getOutputStream();
		while ((len = is.read(buf)) != -1) {
			sos.write(buf, 0, len);
		}
		sos.flush();
		out.clear();
		out = pageContext.pushBody();
	} catch (Exception ex) {
		//ex.printStackTrace();
		response.setContentType("text/html;charset=UTF-8");
		response.setHeader("Content-Disposition", "");
			out.print("抱歉，引起错误原因可能如下：\r\n1、数据更新中，可稍候再试。");
	} finally {
		try {
			if (is != null) {
				is.close(); //关闭输入流 
			}
			if (sos != null) {
				sos.close(); //关闭输出流 
			}
		} catch (Exception e) {
			out.clear();
			out = pageContext.pushBody();
		}
	}
%>
